<template>
  <div class="reports">
    <!-- 卡片视图区域 -->
    <el-card>
      <!-- 2. 为ECharts准备一个具备大小（宽高）的Dom -->
      <div ref="main" style="width: 1200px;height:500px;"></div>
    </el-card>
  </div>
</template>
<script>
import { getReports } from '@/api/reports'
// 1.导入 echarts
import * as echarts from 'echarts'
import _ from 'lodash'
export default {
  name: 'Reports',
  data() {
    return {
      // 需要合并的折线图数据
      options: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },

  async mounted() {
    const myChart = echarts.init(this.$refs.main)
    const { data: res } = await getReports()
    const result = _.merge(res, this.options)
    // 5.使用刚指定的配置项和数据显示图表。
    myChart.setOption(result)
  }
}
</script>
<style lang="scss" scoped></style>
